package priv.tuyou.util;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

/**
 * @Description：Sms短信发送工具类
 * @author：涂有
 * @date 2015年12月17日 下午4:45:56
 */
public class SmsUtil {
	
	private static final String account = "kmjingh_yncw";
	private static final String pswd = "YNcw121212";
	private static final String needstatus = "true";
	private static final String product = ""; 
	
	//短信签名
	public static final String SMS_SIGN = "【清债中国】";
	
	/**
	 * @Description：发送短信
	 * @date 2015年12月17日 下午4:47:36
	 * @param mobile 接收的手机号
	 * @param content 短信内容
	 */
	public static void sendSms(String mobile, String content) {
		
		HttpClient client = new HttpClient(); 		
		PostMethod post = new PostMethod("http://120.24.167.205/msg/HttpSendSM");  		
		post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码 		
		NameValuePair[] data ={
				new NameValuePair("account", account),
				new NameValuePair("pswd", pswd),
				new NameValuePair("mobile", mobile),
				new NameValuePair("msg",SMS_SIGN + content),
				new NameValuePair("needstatus", needstatus),
				new NameValuePair("product", product)}; 		
		post.setRequestBody(data); 		
		
		try {
			client.executeMethod(post);
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 	
//		Header[] headers = post.getResponseHeaders(); 		
//		int statusCode = post.getStatusCode(); 		
//		System.out.println("statusCode:"+statusCode); 		
//		for(Header h : headers){ 			
//			System.out.println(h.toString()); 		
//			} 		
//		String result = null;
//		try {
//			result = new String(post.getResponseBodyAsString().getBytes());
//		} catch (IOException e) {
//			e.printStackTrace();
//		}  		
//		System.out.println(result); //打印返回消息状态 		
		post.releaseConnection();
	}
}
